<!-- Posiciones -->
<div >
    <?php
    if($positions != false)
    {
      
    ?>
    <table class="table table-striped table-bordered table-condensed" width="60%">
        <thead>
            <tr>
                <th colspan="3" style="text-align: center">Posiciones</th>
            </tr>
            <tr>
                <th style="text-align: center">Usuario</th><th style="text-align: center">Puntos</th><th style="text-align: center">Detalle</th>
            </tr>
        </thead>
        <tbody>
        <?php
        foreach($positions as $p)
        {
          
                echo '<tr>';
                echo '<td>'.$p['name'].'</td>';
                echo '<td style="text-align: right">'.$p['points'].'</td>';
                echo '<td style="text-align: center">
                        <i class="icon-search" style="color: #51A351; cursor:hand;" title="ver ficha" onclick="moredetails('.$p['id'].')" ></i>
                      </td>';
                echo '</tr>';
        }
        ?>
        </tbody>
    </table>
    
    <?php
    }
    else
    {
      echo '
          <div class="alert alert-error">
              Ahún no estan disponibles las posiciones.
          </div>
          ';
    }
    ?>
</div>

<div class="modal hide fade" id="modal_fecha">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h3 id="title_date"></h3>
    </div>
    <div class="modal-body">
        <table id="table_team" class="table table-striped table-bordered table-condensed">
            <thead>
                <tr>
                    <th colspan="2" style="text-align: center;">Local</th>
                    <th colspan="2" style="text-align: center">Visita</th>
                    <th style="text-align: center">Jugada</th>
                    <th style="text-align: center">Res.</th>
                    <th style="text-align: center"> - </th>
                </tr>
            </thead>
            <tbody id="table_team_game">
                
            </tbody>
        </table>
        <div id="error_msj" style="color: red"></div>
    </div>
    <div class="modal-footer">
        <a href="#" id="btn_close_pop" class="btn btn-info" onclick="cerrar()">Cerrar</a>
    </div>
</div>


<script>
    function cerrar()
    {
            $('#modal_fecha').modal('hide');
    };
     
    function moredetails(id)
    {
        $('#table_team').css("display", "block");
        $('#error_msj').html('');
        $('#table_team_game').html('');
        $('#title_date').html($("#fecha_game option:selected").html());
        $('#modal_fecha').modal('show');
        
        var data_ajax={
                        type: 'POST',
                        url: "<?php echo base_url(); ?>index.php/user/date_of_user_results",
                        data: { fecha: $('#fecha_game').val(), usr: id },
                        success: function( data ) {
                                                    if(data != 0)
                                                    {	
                                                       //good
                                                       var cant = 0;
                                                       var insert;
                                                       var local;
                                                       var localImg;
                                                       var visita;
                                                       var visitaImg;
                                                       var resulUsr;
                                                       var resulGame;
                                                       var willCard = -1;
                                                       
                                                       $.each(data, function(k,v)
                                                                    {
                                                                        cant++;
                                                                        //Datos de game
                                                                        $.each(v, function(i,j)
                                                                                   {
                                                                                        switch(i)
                                                                                        {
                                                                                            case "localName":
                                                                                                local = j;
                                                                                                break;
                                                                                            
                                                                                            case "localImage":
                                                                                                localImg = j;
                                                                                                break;
                                                                                            
                                                                                            case "visitName":
                                                                                                visita = j;
                                                                                                break;
                                                                                            
                                                                                            case "visitImage":
                                                                                                visitaImg = j;
                                                                                                break;
                                                                                            
                                                                                            case "resultUsr":
                                                                                                resulUsr = j;
                                                                                                break;
                                                                                            
                                                                                            case "resultFin":
                                                                                                resulGame = j;
                                                                                                break;
                                                                                            
                                                                                            case "willCard":
                                                                                                if(j != null)
                                                                                                    willCard = j;
                                                                                                    else
                                                                                                    willCard = -2;
                                                                                                    break;
                                                                                            
                                                                                        }
                                                                                   }
                                                                                  );
                                                                        //
                                                                       insert  = '<td width="25"><img src="<?php echo base_url();?>assets/img/escudos/'+localImg+'" width="25" height="25"></td>';
                                                                       insert += '<td>'+local+'</td>';
                                                                       insert += '<td>'+visita+'</td>';
                                                                       insert += '<td width="25"><img src="<?php echo base_url();?>assets/img/escudos/'+visitaImg+'" width="25" height="25"></td>';
                                                                       insert += '<td style="text-align: center">';
                                                                       if(resulUsr == 1)
                                                                       {
                                                                            insert += "L";
                                                                       }
                                                                       else
                                                                       {
                                                                            if(resulUsr == 2)
                                                                            {
                                                                                insert += "V";
                                                                            }
                                                                            else
                                                                            {
                                                                                if(resulUsr == 0)
                                                                                {
                                                                                    insert += "E";
                                                                                }
                                                                                else
                                                                                {
                                                                                    insert += "-";    
                                                                                }
                                                                            }
                                                                       }

                                                                       if(willCard != -2)
                                                                       {
                                                                            switch(willCard)
                                                                            {
                                                                                case "1":
                                                                                    insert += "/L";
                                                                                    break;
                                                                                
                                                                                case "2":
                                                                                    insert += "/V";
                                                                                    break;
                                                                                
                                                                                case "0":
                                                                                    insert += "/E";
                                                                                    break;
                                                                            }
                                                                       }
                                                                       
                                                                       insert += '</td>';
                                                                       insert += resulGame == 1 ? '<td style="text-align: center">L</td>' : resulGame == 2 ? '<td style="text-align: center">V</td>' : resulGame == 0 ? '<td style="text-align: center">E</td>' : '<td style="text-align: center">-</td>';
                                                                       if(resulGame != -1)
                                                                       {
                                                                            if(resulUsr == resulGame || willCard == resulGame)
                                                                            {
                                                                                 insert += '<td width="25" style="text-align: center; background: #468847;"><i style="margin-top: 4px;" class="icon-ok"></i></td>';
                                                                            }
                                                                            else
                                                                            {
                                                                                 insert += '<td width="25" style="text-align: center; background: #b94a48;"><i style="margin-top: 4px;" class="icon-remove"></i></td>';
                                                                            }
                                                                       }
                                                                       else
                                                                       {
                                                                            insert += '<td width="25" style="text-align: center; background: #F89406;"><i style="margin-top: 4px;" class="icon-minus"></i></td>';
                                                                       }
                                                                       
                                                                       $('#table_team > tbody:last').append('<tr>'+insert+'</tr>');
                                                                    }
                                                                   );
                                                       
                                                       if( cant == 0 )
                                                       {
                                                            $('#table_team').css("display", "none");
                                                            $('#error_msj').html('<strong>No se registro jugada.</strong>');
                                                       }
                                                       else
                                                       {
                                                            $('#error_msj').html('');
                                                       }
                                                    }
                                                    else
                                                    {
                                                        $('#table_team').css("display", "none");
                                                       $('#error_msj').html('<strong>No se registro jugada.</strong>');
                                                    }
                                                  },
                        error: function(){
                                $('#table_team').css("display", "none");
                                $('#error_msj').html('<strong>Ocurrio un error, intente nuevamente la acción.</strong>');
                            },
                        dataType: 'json'
                        };
			$.ajax(data_ajax);
        
			
    }
    
</script>